package org.alex.samples.model;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat;

@Entity
@Table(name = "exam_user")
public class User implements Serializable {

	private static final long serialVersionUID = 1L;

	@NotEmpty(message = "ID不能为空!")
	@Id
	@Column(name = "user_id", length = 10)
	private String id;

	@NotEmpty(message = "姓名不能为空！")
	@Length(min = 1, max = 15, message = "长度不能超过15字符！")
	@Column(name = "user_name", length = 45, nullable = false)
	private String name;

	@Column(name = "password", length = 255, nullable = false)
	private String password;

	@Column(name = "tel", length = 20, nullable = false)
	private String tel;

	@Column(name = "email", length = 255, nullable = false)
	private String email;

	@Column(name = "gender", length = 255, nullable = false)
	private Integer gender;

	@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@Column(name = "last_lock_time")
	private Date lastLockTime;

	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Column(name = "birthday", nullable = false)
	private Date birthday;

	@Column(name = "address", nullable = false)
	private String address;
	
	@Column(name = "login_fail_count")
	private Integer loginFailCount;

	@OneToMany(mappedBy = "user")
	private Set<UserSubject> userSubject;
	
	@OneToOne(cascade = CascadeType.ALL,mappedBy="userRole")
	private ExamUserRole userRole;
	
	@OneToMany(mappedBy = "user")
	private Set<ExamScore> examScore;
	

	public User() {
	}

	public String getId() {
		return this.id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPassword() {
		return this.password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public Integer getGender() {
		return this.gender;
	}

	public void setGender(Integer gender) {
		this.gender = gender;
	}

	public Date getBirthday() {
		return this.birthday;
	}

	public void setBirthday(Date birthday) {
		this.birthday = birthday;
	}

	public String getEmail() {
		return this.email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getTel() {
		return this.tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getAddress() {
		return this.address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Date getLastLockTime() {
		return lastLockTime;
	}

	public void setLastLockTime(Date lastLockTime) {
		this.lastLockTime = lastLockTime;
	}
	
	public Integer getLoginFailCount() {
		return loginFailCount;
	}

	public void setLoginFailCount(Integer loginFailCount) {
		this.loginFailCount = loginFailCount;
	}

	public Set<UserSubject> getUserSubject() {
		return userSubject;
	}

	public void setUserSubject(Set<UserSubject> userSubject) {
		this.userSubject = userSubject;
	}

	public ExamUserRole getUserRole() {
		return userRole;
	}

	public void setUserRole(ExamUserRole userRole) {
		this.userRole = userRole;
	}

	public Set<ExamScore> getExamScore() {
		return examScore;
	}

	public void setExamScore(Set<ExamScore> examScore) {
		this.examScore = examScore;
	}
	
	
}